﻿using System;
using System.Windows.Forms;
using TallyBook.BLL.Service;

namespace TallyBook.UI
{
    public partial class LoginForm : Form
    {
        private readonly IUserService _userService;

        public LoginForm()
        {
            InitializeComponent();
        }


        public LoginForm(IUserService userService)
        {
            InitializeComponent();
            _userService = userService;
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtUserName.Text))
            {
                MessageBox.Show(@"请输入用户名");
                return;
            }
            if (string.IsNullOrEmpty(txtPwd.Text))
            {
                MessageBox.Show(@"请输入密码");
                return;
            }
            string userName = txtUserName.Text;
            string pwd = txtPwd.Text;
            //数据验证逻辑

            if (_userService.Login(userName, pwd))
            {
                var form = new MainForm();
                Hide();
                form.ShowDialog(this);
            }
            else
            {
                MessageBox.Show(@"登陆失败");
            }
        }
    }
}